๐Ÿ“ฆ jasonbanboa / python

๐Ÿ“„ seasons.py ยท 43 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43from datetime import date
import sys
import inflect

p = inflect.engine()


def main():
    date = convert(get_date(input("Date of Birth: ")))
    final_date = p.number_to_words(date).capitalize()
    l = final_date.split(" ")

    for word in l:
        if word == "and":
            l.remove(word)

    print(" ".join(l), "minutes")


def get_date(user_input):
    try:
        year, month, day = user_input.split("-")
        given_date = date(int(year), int(month), int(day))

    except ValueError:
        sys.exit("Invalid date")

    else:
        return given_date


def convert(given_date):
    birth_year = given_date
    today = date.today()
    delta_difference = today - birth_year
    days, times = str(delta_difference).split("days")

    minutes = (int(days) * 24) * 60
    return minutes


if __name__ == "__main__":
    main()